<template>
	<view>
		<view class="block dingwei mainpadding" style="margin-top: 300rpx;">
			
			<view class="dingwei">
				<view class="sishi xiaohei fonweight">{{$t('login.hydl')}}</view>
				<view class="xiahuaxian margin_top6">
					<input type="text" :placeholder="$t('login.qsryhm')" v-model="mobile">
				</view>
				<view class="xiahuaxian margin_top">
					<input type="password" :placeholder="$t('login.qsrmm')" v-model="password">
				</view>
				
				<view class="flexbetween margin_top6">
					<view class="ershiba xiaohei"  @click="tzwjmm">{{$t('login.wjmm')}}</view>
					<view class="ershiba xiaohei" @click="tzljzc">{{$t('login.ljzc')}}</view>
				</view>
				<view class="bigbtn margin_top6" @click="login()" v-if="!liandiantype">{{$t('login.dl')}}</view>
				<view class="bigbtn margin_top6" v-if="liandiantype">{{$t('login.dl')}}</view>
				
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				mobile: "",
				type:false,
				password:"",
				liandiantype:0,
				menutop: 0,
			}
		},
		onLoad() {
			// #ifdef MP-WEIXIN
			this.menutop = uni.getMenuButtonBoundingClientRect().top * 2
			// #endif
		},
		methods: {
			login(){
				let _this = this;
				if(_this.mobile == ''){
					httpRequest.toast(this.$t('login.qsryhm'))
					return;
				}
				// if(!_this.isMobile(_this.mobile)){
				// 	httpRequest.toast("手机号码格式错误!")
				// 	return;
				// }
				if(this.password==""){
					httpRequest.toast(this.$t('login.qsrmm'))
					return false
				} 
				// if(!this.type){
				// 	httpRequest.toast("请认真阅读并勾选用户协议");
				// 	return false;
				// }
				this.liandiantype = 1
				uni.showLoading({
					mask:true,
					title:"请稍候"
				})
				httpRequest.request('/wx/auth/login','POST',{
					username:this.mobile, 
					password:this.password
				}).then(res => {
					if(res.errno == 0){
						uni.hideLoading()
						httpRequest.toast(this.$t('login.dlcg'));
						uni.setStorageSync('token',res.data.token);
						uni.setStorageSync('userinfo',res.data.userInfo);
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}else{
						this.liandiantype = 0
						uni.hideLoading()
						httpRequest.toast(res.errmsg);
					}
				})
			},
			isMobile(value) {
				let a = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(value); 
				return a;
			},
			checkaudio(){
				this.type = !this.type
			},
			// 跳转手机号登录
			tzsjhdl(){
				uni.navigateTo({
					url:'/pages/login/shoujihdl'
				})
			},
			// 跳转忘记密码
			tzwjmm(){
				uni.navigateTo({
					url:'/pages/login/wangjimm'
				})
			},
			// 跳转立即注册
			tzljzc(){
				uni.navigateTo({
					url:'/pages/login/zhuce'
				})
			},
			tzgywm(i) {
				uni.navigateTo({
					url:"/pages/system?type="+i
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	
	.dlbjt{
		width: 100%;
		height: 529rpx;
		position: absolute;
		top: 0;
		left: 0;
		z-index: 0;
	}
	.weixz{
		width: 24rpx;
		height: 24rpx;
		border: 1rpx solid #999999;
		border-radius: 50%;
	}
</style>
